package com.netflexitysolutions.amazonws.s3.internal.operations;

import com.amazonaws.s3.doc._2006_03_01.LoggingSettings;
import com.amazonaws.s3.doc._2006_03_01.SetBucketLoggingStatus;
import com.amazonaws.s3.doc._2006_03_01.SetBucketLoggingStatusResponse;
import com.netflexitysolutions.amazonws.s3.S3;
import com.netflexitysolutions.amazonws.s3.S3LoggingSettings;
import com.netflexitysolutions.amazonws.s3.internal.utils.S3Utils;

public class SetBucketLoggingStatusOperation extends OperationExecutor<SetBucketLoggingStatus, String> {

    private String bucket;
    private S3LoggingSettings loggingSettings;

    public SetBucketLoggingStatusOperation(S3 s3, String bucket, S3LoggingSettings loggingSettings) {
        super(s3);
        this.bucket = bucket;
        this.loggingSettings = loggingSettings;
    }

    @Override
    protected String call(SetBucketLoggingStatus request) {
        request.setBucket(bucket);

        LoggingSettings ls = new LoggingSettings();
        ls.setTargetBucket(loggingSettings.getTargetBucket());
        ls.setTargetPrefix(loggingSettings.getTargetPrefix());
        ls.setTargetGrants(S3Utils.convert(loggingSettings.getAcl()));

        injectCredentials(request, "SetBucketLoggingStatus", getS3().getAccessKey(), getS3().getSecretKey());
        SetBucketLoggingStatusResponse response = getS3().getService().setBucketLoggingStatus(request);
//Since Amazon returns empty object we have to return something meanless
        return "";
    }
}
